package com.roadjava.rbac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.roadjava.rbac.bean.entity.UserDO;
import com.roadjava.rbac.bean.req.user.UserPageReq;
import com.roadjava.rbac.bean.vo.UserVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
* @author 27249
* @description 针对表【user(用户表)】的数据库操作Mapper
* @createDate 2024-11-01 21:13:03
* @Entity com.roadjava.rbac.entity.User
*/
public interface UserMapper extends BaseMapper<UserDO> {
    @Insert("INSERT INTO user (username, pwd, real_name,sex) VALUES (#{username}, #{pwd}, #{real_name},#{sex})")
    void addUser(@Param("username") String username, @Param("pwd") String pwd, @Param("real_name") String real_name,@Param("sex") String sex);

    @Update("UPDATE user SET real_name = #{realName}, email = #{email}, phone = #{phone}, sex = #{sex} WHERE id = #{id}")
    void updateUserInfo(
            @Param("id") Long id,
            @Param("realName") String realName,
            @Param("email") String email,
            @Param("phone") String phone,
            @Param("sex") String sex
    );

    @Select("SELECT role_id FROM link_user_role WHERE user_id = #{id}")
    Long postRole(@Param("id") Long id); // 确保 param 名称与 SQL 映射一致

    Long queryCount(UserPageReq pageReq);

    List<UserVO> queryList(UserPageReq pageReq);
    @Select("SELECT username, real_name, email, phone, sex FROM user")
    List<UserDO> emptyList();
}




